﻿using Business;
using Entity;
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.UI;

namespace NetFlow
{
    public partial class Overview : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string encodedFilePath = Request.QueryString["file"];
            string filePath = "";
            if (!string.IsNullOrEmpty(encodedFilePath))
            {
                filePath = HttpUtility.UrlDecode(encodedFilePath);
                Session["FilePath"] = filePath;

                
            }else
            {
                filePath = Session["FilePath"].ToString();
            }

            // 调用 Business 层的方法获取数据
            AnalysisBusiness analysisBusiness = new AnalysisBusiness();
            List<NetFlowEntity> netFlowList = analysisBusiness.ParseNetFlowData(filePath);

            if (netFlowList != null && netFlowList.Count > 0)
            {
                // 将数据转换为 JSON 格式并传递到前端
                string jsonData = new JavaScriptSerializer().Serialize(netFlowList);
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ChartData", $"var netFlowData = {jsonData};", true);
                //Response.Write("jsondata:"+jsonData);
            }
            else
            {
                Response.Write("No data available.");
            }
        }
    }
}